﻿<?php

global $config;
if (isset($_GET['act'])) $act = $_GET['act'];

$view_url = "index.php?mod=cmt&act=view&id=";
?>
<?php

if ($act == "list") {
?>
    <h3 class='action-title'>Thống kê nhận xét</h3>
    <?php
    if (isset($_GET['task']) && $_GET['task'] == 'delete') {
        if (isset($_GET['id'])) $id = $_GET['id'];
        $sql = "delete from dnhotel where id = $id";
		$pg = new PgSQL();
		$pg->connect();
        if ($pg->query($sql)) notice("Đả xóa khách sạn.");
        else notice("Lổi: chưa cập nhật được dữ liệu.");
		$pg->disconnect();
    }
    ?>
    <div id="list-posts">
        <div class="header-list">
            <label class="header-username">Tên Khách Sạn</label>
            <label class="header-email">Địa Chỉ</label>
            <label class="header-edit">Số nhận xét</label>
            <div class="clear"></div>
        </div>
        <?php
            $page = (isset($_GET['page'])) ? $_GET['page'] : 1;
            $limit = $config['news_per_page'];
            $start = $start = $limit * ($page - 1);
            $sql = "select a.id, a.name, a.address, count(b.content) as cmt  from dnhotel as a, comment as b where a.id=b.id GROUP BY a.id, a.name, a.address";// limit $limit offset $start";
			$pg = new PgSQL();
			$pg->connect();
			$data = $pg->query($sql);
            //$data = $db->get_data($db->query($sql));
            
            if ($pg->numberRows() != 0) :
            while ($row = pg_fetch_object($data)) {
        ?>
        <div class="row-post">
            <label class="header-username"><?php echo $row->name; ?></label>
            <label class="header-email"><?php echo $row->address ?></label>
            <label class="header-edit"><a href="<?php echo $view_url.$row->id ?>" class="edit-post" title="Xem tất cả nhận xét"><?php echo $row->cmt ?></a></label>
            <div class="clear"></div>
        </div>
        <?php
            }
            endif;
            ViewPages($config['news_per_page'], "contact", "contact");
			$pg->disconnect();
        ?>
    </div>

<?php
} else if ($act == "view") {
	
	$id = (isset($_GET['id'])) ? $_GET['id'] : 0;
	
	$sql = "select name from dnhotel where id = ".$id;
	$pg = new PgSQL();
	$pg->connect();
	$data = $pg->query($sql);
    //$data = $db->fetch_array($db->query($sql));
    if ($row = pg_fetch_object($data)) {
		echo "<h3 class='action-title'>Các nhận xét về khách sạn ".$row->name."</h3>";
	}
?>
<div id="list-posts">
	<div class="header-list">
		<label class="header-username">Họ tên người nhận xét</label>
		<label class="header-email">Thời gian nhận xét</label>
		<label class="header-edit">Nội dung</label>
		<div class="clear"></div>
	</div>
<?php
	$sql = "select * from comment where id = ".$id;
	$data = $pg->query($sql);
	while ($row = pg_fetch_object($data)) {
?>
	<div class="row-post">
		<label class="header-username"><?php echo $row->creater; ?></label>
		<label class="header-email"><?php echo $row->date ?></label>
		<label class="header-edit"><?php echo $row->content ?></label>
		<div class="clear"></div>
	</div>
<div> <!-- -->
<?php
	}
	$pg->disconnect();
}
?>